﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpShare.Collections;

namespace SharpShare.Utilities {
    public static class ObjectCache<TValue> where TValue : class {
        public static class ByKey<TKey> {
            private static WeakDictionary<TKey, TValue> _values = new WeakDictionary<TKey, TValue>();

            public static TValue GetOrCreate(TKey key, Func<TKey, TValue> valueFactory) {
                return _values.GetOrAdd(key, valueFactory);
            }
        }
    }
}
